home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / SOURCE / INPUT.CPP < prev    next >
C/C++ Source or Header  |  1994-05-25  |  6KB  |  205 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module input.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/input.cpp 1.1 1994/05/25 22:19:57 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #include <ctype.h>
  32. #include <stdlib.h>
  33. #include "types.h"
  34. #include "disk_io.h"
  35. #include "global.h"
  36. #include "input.h"
  37.  
  38. /* ----------------------------------------------------------------------- */
  39. /* User Input                                                              */
  40. /* ----------------------------------------------------------------------- */
  41.  
  42. static void wait_for_key (void)
  43. {
  44.     printx ("\nPress any Key\n");
  45.     getx();
  46. }
  47.  
  48. int ask_for_drive_number (void)
  49. {
  50.     int drives_found = 0;
  51.     int drive_table[] = {0,0,0,0,0,0,0,0,0};
  52.  
  53.     int no_of_drives = get_no_of_drives ();
  54.  
  55.     for (int i=0x80; i<0x80 + no_of_drives; i++) if (get_disk_type(i) == 3)
  56.     {
  57.         drive_table[drives_found++] = i;
  58.         if (drives_found == 10)
  59.             error ("Too many drives found");
  60.     }
  61.  
  62.     if (drives_found == 0)
  63.         error ("No Compatible Harddisk found");
  64.     if (drives_found == 1) return (drive_table[0]);
  65.  
  66.     printx ("Which Drive (");
  67.  
  68.     for (i=0;i<drives_found;i++) printx ("%u=0x%02X/",i+1,drive_table[i]);
  69.     printx ("\b)? ");
  70.  
  71.     while (true)
  72.     {
  73.         i = getx ();
  74.         if (isdigit (i)) if (i > '0') if (drive_table[i - '1']) break;
  75.     }
  76.     printx ("%c\n",i);
  77.     return (drive_table[i - '1']);
  78. }
  79.  
  80. int ask_for_partition_number (partition_info parts[])
  81. {
  82.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) +
  83.          (parts[2].system != 0) + (parts[3].system != 0);
  84.  
  85.     if (number_of_partitions == 0)
  86.         error ("No valid partition found");
  87.  
  88.     if (number_of_partitions == 4)
  89.         error ("No free partition");
  90.  
  91.     if (number_of_partitions == 1)
  92.     {
  93.         wait_for_key();
  94.         for (int i=0;i<4;i++) if (parts[i].system) return i;
  95.     }
  96.  
  97.     printx ("\nWhich Partition do you want to split (");
  98.  
  99.     for (int i=0;i<4;i++) if (parts[i].system) printx ("%u/",i+1);
  100.     printx ("\b)? ");
  101.  
  102.     while (true)
  103.     {
  104.         i = getx ();
  105.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i-'1'].system) break;
  106.     }
  107.     printx ("%c\n",i);
  108.     return (i-'1');
  109. }
  110.  
  111. dword ask_for_new_start_cylinder (int start_cylinder, int min_cylinder,int max_cylinder, int sectors_per_cylinder)
  112. {
  113.     int akt_cylinder = min_cylinder;
  114.  
  115.     printx ("Enter start cylinder for new partition (%u - %u):\n\n",min_cylinder,max_cylinder);
  116.     printx ("Use the cursor keys to choose the cylinder, <enter> to continue\n\n");
  117.     printx ("Old partition      Cylinder       New Partition\n");
  118.  
  119.     while (true)
  120.     {
  121.         double oldsize = (akt_cylinder - start_cylinder) * (double) sectors_per_cylinder / 2048;
  122.         double newsize = (max_cylinder - akt_cylinder + 1) * (double) sectors_per_cylinder / 2048;
  123.  
  124.         printf (" %6.1f MB          %4u           %6.1f MB\r", oldsize, akt_cylinder, newsize);
  125.  
  126.         int input = getx ();
  127.         if (input == '\r')
  128.         {
  129.             printx (" %6.1f MB          %4u           %6.1f MB\n\n", oldsize, akt_cylinder, newsize);
  130.             return (akt_cylinder);
  131.         }
  132.         else if (input != 0) continue;
  133.  
  134.         input = getx ();
  135.         switch (input)
  136.         {
  137.             case 75:
  138.                 if (akt_cylinder > min_cylinder) akt_cylinder--;
  139.                 break;
  140.             case 77:
  141.                 if (akt_cylinder < max_cylinder) akt_cylinder++;
  142.                 break;
  143.             case 72:
  144.                 if (akt_cylinder - 10 >= min_cylinder) akt_cylinder -= 10;
  145.                 break;
  146.             case 80:
  147.                 if (akt_cylinder + 10 <= max_cylinder) akt_cylinder += 10;
  148.                 break;
  149.         }
  150.     }
  151. }
  152.  
  153. void ask_for_write_permission (void)
  154. {
  155.     printx ("\nReady to write new partition scheme to disk\n");
  156.     printx ("Do you want to proceed (y/n)? ");
  157.  
  158.     int character;
  159.     do character = getx(); while ((character != 'y') && (character != 'n'));
  160.     printx ("%c\n",character);
  161.     if (character == 'n') exit (0);
  162. }
  163.  
  164. boolean ask_if_continue (void)
  165. {
  166.     printx ("\nDo you want to continue or reedit the partition table (c/r)? ");
  167.  
  168.     int character;
  169.     do character = getx(); while ((character != 'c') && (character != 'r'));
  170.     printx ("%c\n",character);
  171.     if (character == 'r') return (false);
  172.     return (true);
  173. }
  174.  
  175. boolean ask_if_save (void)
  176. {
  177.     int character;
  178.  
  179.     printx ("Do you want to make a backup copy of your root- and bootsector before\nproceeding (y/n)? ");
  180.     do character = getx(); while ((character != 'y') && (character != 'n'));
  181.     printx ("%c\n\n",character);
  182.     if (character == 'n') return (false);
  183.  
  184.     printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? ");
  185.     do character = getx(); while ((character != 'y') && (character != 'n'));
  186.     printx ("%c\n\n",character);
  187.     if (character == 'n')
  188.     {
  189.         printx ("Please read the file FIPS.DOC!\n");
  190.         exit (0);
  191.     }
  192.  
  193.     return (true);
  194. }
  195.  
  196. void ask_if_proceed (void)
  197. {
  198.     printx ("Do you want to proceed (y/n)? ");
  199.  
  200.     int character;
  201.     do character = getx(); while ((character != 'y') && (character != 'n'));
  202.     printx ("%c\n",character);
  203.     if (character == 'n') exit (0);
  204. }
  205.